package com.xjscrm.console.service.common.corpapplication.impl;

import com.xjscrm.common.entity.CorpApplication;
import com.xjscrm.console.config.datasource.DynamicDataSourceContextHolder;
import com.xjscrm.console.mapper.CorpApplicationMapper;
import com.xjscrm.console.service.common.corpapplication.CorpApplicationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class CorpApplicationServiceImpl implements CorpApplicationService {

    @Autowired
    private CorpApplicationMapper corpApplicationMapper;

    @Override
    public CorpApplication getByCorpId(String corpId) {
        String dataSourceKey = DynamicDataSourceContextHolder.getDataSourceKey();
        log.info("当前数据源为：{}", dataSourceKey);
        return corpApplicationMapper.selectByCorpId(corpId);
    }

    @Override
    public Boolean insert(CorpApplication corpApplication) {
        corpApplicationMapper.insertSelective(corpApplication);
        return true;
    }

    @Override
    public Boolean update(CorpApplication corpApplication) {
        corpApplicationMapper.updateByPrimaryKeySelective(corpApplication);
        return true;
    }
}
